<?php
require_once "includes/config.php";
$action = $_REQUEST['action'];

if($action==1)
{
    $product_id = $_REQUEST['product_id'];
    $sql = mysql_query("select product_code,product_id from tbl_wholeseller_product where product_id='$product_id'") or die(mysql_error());
    $cnt = mysql_num_rows($sql);
    if($cnt>0)
    {
        $i=1;
        $html = '<div class="popup_box_in"><div style="float:left; text-align:right; width:98%; padding:5px;"><span style="cursor:pointer;font-weight:bold;" onclick="$(\'#code_box\').hide();$(\'#exp_'.$product_id.'\').attr(\'src\',\'./images/plus_ico.png\');">x</span></div><table width="100%">';
        $html.='<tr><th>No.</th><th>Product Code</th><th>Action</th></tr>';
        while($row = mysql_fetch_array($sql))
        {
            $html.='<tr><td>'.$i.'</td><td><input type="text" size="9" value="'.$row['product_code'].'" name="code_'.$row['product_id'].'" id="code_'.$row['product_id'].'" maxlength="10" /></td><td><input type="button" name="upd_'.$row['product_id'].'" id="upd_'.$row['product_id'].'" value="Update" onclick="update_code1('.$row['product_id'].')" /></td></tr>';
            $i++;
        }//while
        $html.='</table></div>';
    }//if
    else {
        $html = 'fail';
    }//else
    
    echo $html;
}
else
{
    $code_id = $_REQUEST['code_id'];
    $code = $_REQUEST['code'];
    
    $qry = mysql_query("update tbl_wholeseller_product set product_code = '".$code."' where product_id='".$code_id."'") or die();
    if($qry)
        echo 'suc';
    else
        echo 'fail';
}
?>